package model;

/**
 * Currency in this class is in <em>cents</em>. 
 * e.g if telstraClear is 123456, it's value in the real world is $1234.56 .
 * Meaning all in types in this class represent currency
 * 
 * @author Paul Daniel Iway
 *
 */
public class Record {
	
	private int in;
	
	private int telstraClear;
	private int vodafone;
	private int grocery;
	private int internet;
	private int electricity;
	private int misc;
	
	private int creditCard;
	private int nationalBank;
	
	private String comments;

	public int getIn() {
		return in;
	}

	public int getTelstraClear() {
		return telstraClear;
	}

	public int getVodafone() {
		return vodafone;
	}

	public int getGrocery() {
		return grocery;
	}

	public int getInternet() {
		return internet;
	}

	public int getElectricity() {
		return electricity;
	}

	public int getMisc() {
		return misc;
	}

	public int getCreditCard() {
		return creditCard;
	}

	public int getNationalBank() {
		return nationalBank;
	}

	public String getComments() {
		return comments;
	}

	public void setIn(int in) {
		this.in = in;
	}
	
	public void setIn(String in) {
		this.in = getMoneyFormat(in);
	}

	public void setTelstraClear(int telstraClear) {
		this.telstraClear = telstraClear;
	}
	
	public void setTelstraClear(String telstraClear) {
		this.telstraClear = getMoneyFormat(telstraClear);
	}

	public void setVodafone(int vodafone) {
		this.vodafone = vodafone;
	}
	
	public void setVodafone(String vodafone) {
		this.vodafone = getMoneyFormat(vodafone);
	}

	public void setGrocery(int grocery) {
		this.grocery = grocery;
	}
	
	public void setGrocery(String grocery) {
		this.grocery = getMoneyFormat(grocery);
	}

	public void setInternet(int internet) {
		this.internet = internet;
	}
	
	public void setInternet(String internet) {
		this.internet = getMoneyFormat(internet);
	}

	public void setElectricity(int electricity) {
		this.electricity = electricity;
	}
	
	public void setElectricity(String electricity) {
		this.electricity = getMoneyFormat(electricity);
	}

	public void setMisc(int misc) {
		this.misc = misc;
	}
	
	public void setMisc(String misc) {
		this.misc = getMoneyFormat(misc);
	}

	public void setCreditCard(int creditCard) {
		this.creditCard = creditCard;
	}
	
	public void setCreditCard(String creditCard) {
		this.creditCard = getMoneyFormat(creditCard);
	}
	
	public void setNationalBank(int nationalBank) {
		this.nationalBank = nationalBank;
	}
	
	public void setNationalBank(String nationalBank) {
		this.nationalBank = getMoneyFormat(nationalBank);
	}

	public void setComments(String comments) {
		this.comments = comments;
	}
	
	private int getMoneyFormat(String str) {
		int result = 0;
		try {
			result = getMoneyFormat(Double.valueOf(str.replaceAll(",", "")));
		} catch(NumberFormatException e) {
			
		}
		return result;
	}
	
	private int getMoneyFormat(Double val) {
		return Double.valueOf(val*100).intValue();
	}
	
	
	public int getTotalBills() {
		return telstraClear + vodafone + grocery + internet + electricity + misc;
	}
	
	public int getTotalExpenses() {
		return getTotalBills() + creditCard + nationalBank;
	}
	
	public int getSaved() {
		return in - getTotalExpenses();
	}

}
